<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			*{
				padding: 0%;
				margin: 0%;
			}
			#box{
				width: 200px;
				height: 200px;
				background-color: pink;
				position: absolute;
				top: 50px;
			}
		</style>
	</head>
	<body>
		<button id="btn">动画</button>
		<div id="box"></div>
	</body>
	<script>
		let btn = document.getElementById('btn');
		let box = document.getElementById('box');
		let num = 0;
		let timer = null;
		//绑定事件
		btn.onclick = function(){
			clearInterval(timer);
			//定时器
			timer = setInterval(function() {
				//边界处理
				if(box.offsetLeft === 500) {
					clearInterval(timer);
				}else{
					box.style.left = box.offsetLeft + 10 + 'px';
				}
			},30)
		}
	</script>
</html>